﻿using System;
using System.IO;
using Microsoft.SolverFoundation.Services;
using DigitalRune.Windows.TextEditor.Highlighting;
using System.Windows.Forms;

namespace Zove.Desktop {
    public partial class OMLEditor : EditingForm {
        public OMLEditor()
            : base() {
            base.GetTextEditorControl().Document.HighlightingStrategy
                = HighlightingManager.Manager.FindHighlighter("OML");
        }

        public OMLEditor(string fileName)
            : base(fileName) {
            base.GetTextEditorControl().Document.HighlightingStrategy
                = HighlightingManager.Manager.FindHighlighter("OML");
        }

        public override void Execute() {
            try {
                StringReader reader = new StringReader(base.GetTextEditorControl().Text);

                SolverContext context = SolverContext.GetContext();
                context.ClearModel();
                context.LoadModel(FileFormat.OML, reader);

                Solution solution = context.Solve();
                Report report = solution.GetReport();


                ConsoleWindow output = new ConsoleWindow();

                output.MdiParent = this.MdiParent;
                output.Show();

                Console.WriteLine(report);
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
